import Vue from "vue";
import VueRouter from "vue-router";
import HomeView from "../views/HomeView.vue";

Vue.use(VueRouter);

const routes = [
  {
    path: "/",
    name: "Home",
    redirect: "/index",
    meta: {
      keepAlive: true,
    },
    component: HomeView,
    children: [
      {
        path: "index",
        name: "Index",
        component: () => import("../views/IndexView.vue"),
        meta: {
          title: "烘焙帮首页",
          keepAlive: true,
        },
      },
      {
        path: "show",
        name: "Show",
        meta: {
          title: "烘焙圈",
        },
        component: () => import("../views/ShowView.vue"),
      },
      {
        path: "question",
        name: "Queestion",
        meta: {
          title: "烘焙帮问答",
        },
        component: () => import("../views/QuestionView.vue"),
      },
      {
        path: "client",
        name: "Client",
        meta: {
          title: "个人中心",
        },
        component: () => import("../views/ClientView.vue"),
      },
    ],
  },
  {
    path: "/recipe_list/:kw?",
    name: "Recipelist",
    meta: {
      title: "搜索结果",
    },
    component: () => import("../views/RecipeList.vue"),
  },
  {
    path: "/search",
    name: "Search",
    meta: {
      title: "烘焙帮搜索页",
    },
    component: () => import("../views/SearchView.vue"),
  },
  {
    path: "/login",
    name: "Login",
    meta: {
      title: "烘焙帮登录页",
    },
    component: () => import("../views/LoginView.vue"),
  },
  {
    path: "/register", //注册页面
    name: "Register",
    meta: {
      title: "烘焙帮注册页",
    },
    component: () => import("../views/RegisterView.vue"),
  },
  {
    path: "/account",
    name: "Account", //个人设置
    meta: {
      title: "烘焙帮个人信息",
    },
    component: () => import("../views/AccountView.vue"),
  },
  {
    path: "/clienttds/:activeName",
    name: "ClientTds", //作品//食谱//问题
    meta: {
      title: "个人作品",
    },
    component: () => import("../views/ClientTds.vue"),
  },
  {
    path: "/edit",
    name: "Edit", //个人作品编辑
    meta: {
      title: "个人作品编辑",
    },
    component: () => import("../views/Edit.vue"),
  },
  {
    path: "/recipe",
    name: "Recipe",
    meta: {
      title: "创建食谱", //创建食谱
    },
    component: () => import("../views/RecipeView.vue"),
  },
  {
    path: "/questions",
    name: "Questions", //问答//个人主页修改//其他页面肯能也是一样的
    meta: {
      title: "提出问题", //  问题编辑
    },
    component: () => import("../views/Questions.vue"),
  },
  {
    path: "/collect",
    name: "collect", //收藏页面
    meta: {
      title: "我的收藏",
    },
    component: () => import("../views/Collect.vue"),
  },
  {
    path: "/profile",
    name: "Profile",
    meta: {
      title: "设置",
    },
    component: () => import("../views/ProfileView.vue"),
    children: [],
  },
  {
    path: "/addr_info", //地址信息
    name: "addr_info",
    meta: {
      title: "收货地址",
      keepAlive: false,
    },
    component: () => import("../views/AddrInfo.vue"),
  },
  {
    path: "/classify", //学烘焙食谱分类
    name: "Classify",
    meta: {
      title: "食谱分类",
    },
    component: () => import("../views/ClassifyView.vue"),
  },
  {
    path: "/remind", //学烘焙导航右侧
    name: "Remind",
    meta: {
      title: "消息",
    },
    component: () => import("../views/RemindView.vue"),
  },
  {
    path: "/follow/:activeNames",
    name: "Follow", //关注与粉丝
    meta: {
      title: "关注与粉丝",
    },
    component: () => import("../views/Follow.vue"),
  },
  {
    path: "/checkconis", //帮贡
    name: "checkConis",
    meta: {
      title: "我的帮贡",
    },
    component: () => import("../views/CheckConis.vue"),
  },
  {
    path: "/medalLibrary", //我的勋章
    name: "MedalLibrary",
    meta: {
      title: "我的勋章",
    },
    component: () => import("../views/MedalLibrary.vue"),
  },
  {
    path: "/university", //学烘焙视频学堂
    name: "University",
    meta: {
      title: "视频学堂",
    },
    component: () => import("../views/UniversityView.vue"),
  },
  {
    path: "/baike", //学烘焙技巧百科
    name: "Baike",
    meta: {
      title: "技巧百科",
    },
    component: () => import("../views/BaikeView.vue"),
  },
  {
    path: "/shopdetail", //学烘焙新手教程
    name: "ShopDetail",
    meta: {
      title: "新手教程",
    },
    component: () => import("../views/ShopDetail.vue"),
  },
  {
    path: "/works/:id",
    name: "Works",
    meta: {
      title: "食谱详情",
    },
    component: () => import("../views/WorksView.vue"),
  },
  {
    path: "/newbie",
    name: "Newbie",
    meta: {
      title: "烘焙帮",
    },
    component: () => import("../views/NewbieView.vue"),
  },
  {
    path: "/answer/:id", //问答详情页面
    name: "answer",
    meta: {
      title: "问答详情",
    },
    component: () => import("../views/AnswerView.vue"),
  },
  {
    path: "/term",
    name: "Term",
    meta: {
      title: "服务条款",
    },
    component: () => import("../views/TermView.vue"),
  },
  {
    path: "/policy",
    name: "Policy",
    meta: {
      title: "隐私政策",
    },
    component: () => import("../views/PolicyView.vue"),
  },
  {
    path: "/about",
    name: "About",
    meta: {
      title: "关于我们",
    },
    component: () => import("../views/AboutView.vue"),
  },
  {
    path: "/suggest",
    name: "Suggest",
    meta: {
      title: "意见反馈",
    },
    component: () => import("../views/Suggestion.vue"),
  },
  {
    path: "/history",
    name: "History",
    meta: {
      title: "浏览历史",
    },
    component: () => import("../views/HistoryView.vue"),
  },
  {
    path: "/apply",
    name: "Apply",
    meta: {
      title: "达人申请",
    },
    component: () => import("../views/ApplyView.vue"),
  },
  {
    path: "/exchange",
    name: "Exchange",
    meta: {
      title: "帮贡兑换",
    },
    component: () => import("../views/Exchange.vue"),
  },
  {
    path: "/workdetail",
    name: "Workdetail",
    meta: {
      title: "作品详情",
    },
    component: () => import("../views/WorkDetail.vue"),
  },
  {
    path: "/usercenter",
    name: "Usercenter",
    meta: {
      title: "用户主页",
    },
    component: () => import("../views/UserCenter.vue"),
  },
  {
    path: "/publish",
    name: "Publish",
    meta: {
      title: "发评论",
    },
    component: () => import("../views/PublishView.vue"),
  },
];

const router = new VueRouter({
  mode: "history",
  base: process.env.BASE_URL,
  routes,
});

router.beforeEach((to, from, next) => {
  document.title = to.meta.title;
  // 回到首页需要保活
  if (to.path == "/index") {
    to.meta.keepAlive = true;
  } else {
    to.meta.keepAlive = false;
  }
  next();
});

export default router;
